using System;
using System.Collections.Generic;
using System.Text;

namespace virtuaPol.vpTest
{
    class TestSuite
    {
        private IList<ITestCase> cases;
        public IList<ITestCase> TestCases
        {
            get { return cases; }
        }

        public int Count
        {
            get { return cases.Count; }
        }

        private int success = 0;
        public int Success
        {
            get { return success; }
        }

        private string report = "";
        public string Report
        {
            get { return report; }
        }

        public TestSuite()
        {
            cases = new List<ITestCase>();
        }

        public void addTestCase(ITestCase t)
        {
            cases.Add(t);
        }

        public void execute()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("----------------------------------\n");
            sb.Append("--------- Starting tests: --------\n");
            foreach (ITestCase c in cases)
            {
                c.initialize();
                success +=
                    (c.execute() ? 1 : 0);
                c.cleanup();
                sb.Append("----------------------------------\n");
                sb.Append(c.getReport());
            }
            sb.Append("----------------------------------\n");
            sb.Append("--------- Result: ----------------\n");
            sb.Append("----------------------------------\n");
            sb.Append(success.ToString() 
                + " of " + cases.Count 
                + " tests executed successfully.\n");

            report = sb.ToString();
        }
    }
}
